package com.twu.biblioteca;

/**
 * Created by ubuntu on 4/22/14.
 */
public class Book {
    private String title;
    private int totalCopies = 1;
    private int lendedCount = 0;

    public Book(String title) {
        this.title = title;
    }

    @Override
    public String toString() {
        return title + ", available:" + (totalCopies > 0) + " " + totalCopies;
    }

    public void addCopy() {
        totalCopies++;
    }

    public String getTitle() {
        return title;
    }

    public int checkOut() {
        lendedCount++;
        return totalCopies--;
    }

    public boolean isLended() {
        return lendedCount > 0;
    }

    public int getAvailableCopies() {
        return totalCopies;
    }

    public boolean checkIn() {
        if (lendedCount > 0) {
            addCopy();
            lendedCount--;
            return true;
        }
        return false;
    }
}
